Guided Practice 4.1 - Solution

The question was:

Consider the following data definition:

;; A ListOfStrings (LOS) is one of
;; -- empty
;; -- (cons String LOS)

Which of the following expressions have values that are LOS's?

Here are the answers:

  1. (cons "abc" empty) Answer: Yes. empty is a LOS and "abc" is a string, so (cons "a" empty) is a LOS
  2. (cons "bcd") Answer: No. This expression has no value, because cons has the wrong number of arguments.
  3. (cons "cde" (cons "ef" empty)) Answer: Yes. This is a LOS.
  4. (cons "3" (cons "4" empty)) Answer: Yes. This is also a LOS.
  5. (cons 3 (cons 4 empty)) Answer: No. 3 and 4 are numbers, not strings.

Last modified: Wed Aug 24 21:34:01 Eastern Daylight Time 2016